package com.palm.hubo2o.network;

import android.app.Activity;
import android.content.Intent;

import com.palm.hubo2o.model.User;
import com.palm.hubo2o.ui.LoginActivity;

/**
 * Created by wongqi on 16/6/14.
 */
public class PalmSession {
    public static final int login_code = 999;
    private static User global;


    public static void setSession(User user) {
        global = user;
    }

    public static boolean isLogin() {
        return global != null;
    }


    public static void login(Activity activity) {
        login(activity, login_code);
    }

    public static void login(Activity activity, int code) {
        activity.startActivityForResult(new Intent(activity, LoginActivity.class), code);
    }


    public static User getGlobal() {
        return global;
    }

    public static void logout() {
        global = null;
    }

    static void wrapRequest(Request request) {
        if (global != null) {
            request.setSessionId(global.getSessionId());
            request.setStationId(global.getStationId());
            request.setUserId(global.getUserId());
        }

    }
}
